/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.click.app.webapp.action;

import com.click.app.model.Laundry;
import com.click.app.model.LaundryPayment;
import com.click.app.model.PeriodPaymentLaundry;
import com.click.app.service.LaundryManager;
import com.click.app.service.LaundryPaymentManager;
import com.click.app.service.PeriodPaymentLaundryManager;
import java.util.List;

/**
 *
 * @author ronald
 */
public class LaundryPaymentAction  extends BaseAction {

    private Long id;
    private LaundryManager laundryManager;
    private Laundry laundry;
    private Float newAmount;
    private Float amountPayed;
    private PeriodPaymentLaundryManager periodPaymentLaundryManager;
    private PeriodPaymentLaundry periodPaymentLaundry;
    private LaundryPayment laundryPayment;
    private LaundryPaymentManager laundryPaymentManager;
    private List<LaundryPayment> laundryPaymentList;
    
    public String choicedLaundry(){
        if(id == null)
            id = (Long)getSession().getAttribute("lPid");
        
        if (id != null){
            laundry = laundryManager.get(id);
            periodPaymentLaundry = periodPaymentLaundryManager.findCurrentPeriodByLaundry(laundry.getId());
            laundryPaymentList = periodPaymentLaundry.getLaundryPaymentList();
            getSession().setAttribute("lPid", laundry.getId());
            getSession().setAttribute("lPPeridodid", periodPaymentLaundry.getId());
        }
        return SUCCESS;
    }

    public String asignNewPaymentLaundry(){
        laundry = laundryManager.get((Long)getSession().getAttribute("lPid"));
        return SUCCESS;
    }

    public String saveNewAmount(){
        System.out.println(" saveNewAmount() ");
        if(laundryPayment.getAmount() > 0 && laundryPayment.getDate() != null &&
           laundryPayment.getCode() != null && laundryPayment.getCode().length() > 0){
           periodPaymentLaundry = periodPaymentLaundryManager.get((Long)getSession().getAttribute("lPPeridodid"));
           laundryPayment.setPeriodPaymentLaundry(periodPaymentLaundry);
           laundryPaymentManager.save(laundryPayment);
           saveMessage(getText("laundryPayment.save"));
           return SUCCESS;
        }
        
        System.out.println(" end - saveNewAmount() ");
        return SUCCESS;
    }

    public String deletePaymentLaundry(){
        System.out.println(" deletePaymentLaundry() ");
        if(id != null ){
            laundryPaymentManager.remove(id);
        }
        System.out.println(" end - deletePaymentLaundry() ");
        return SUCCESS;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public LaundryManager getLaundryManager() {
        return laundryManager;
    }

    public void setLaundryManager(LaundryManager laundryManager) {
        this.laundryManager = laundryManager;
    }

    public Laundry getLaundry() {
        return laundry;
    }

    public void setLaundry(Laundry laundry) {
        this.laundry = laundry;
    }

    public Float getAmountPayed() {
        return amountPayed;
    }

    public void setAmountPayed(Float amountPayed) {
        this.amountPayed = amountPayed;
    }

    public Float getNewAmount() {
        return newAmount;
    }

    public void setNewAmount(Float newAmount) {
        this.newAmount = newAmount;
    }

    public PeriodPaymentLaundryManager getPeriodPaymentLaundryManager() {
        return periodPaymentLaundryManager;
    }

    public void setPeriodPaymentLaundryManager(PeriodPaymentLaundryManager periodPaymentLaundryManager) {
        this.periodPaymentLaundryManager = periodPaymentLaundryManager;
    }

    public PeriodPaymentLaundry getPeriodPaymentLaundry() {
        return periodPaymentLaundry;
    }

    public void setPeriodPaymentLaundry(PeriodPaymentLaundry periodPaymentLaundry) {
        this.periodPaymentLaundry = periodPaymentLaundry;
    }

    public LaundryPayment getLaundryPayment() {
        return laundryPayment;
    }

    public void setLaundryPayment(LaundryPayment laundryPayment) {
        this.laundryPayment = laundryPayment;
    }

    public LaundryPaymentManager getLaundryPaymentManager() {
        return laundryPaymentManager;
    }

    public void setLaundryPaymentManager(LaundryPaymentManager laundryPaymentManager) {
        this.laundryPaymentManager = laundryPaymentManager;
    }

    public List<LaundryPayment> getLaundryPaymentList() {
        return laundryPaymentList;
    }

    public void setLaundryPaymentList(List<LaundryPayment> laundryPaymentList) {
        this.laundryPaymentList = laundryPaymentList;
    }

}
